<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorate="~{shared/layout}">
<head>
    <meta charset="UTF-8"/>
    <title>管理系统</title>
    <link th:href="@{/custom/css/admin.css}" rel="stylesheet"/>
</head>
<body layadmin-themealias="ocean" class="layui-layout-body">
<div layout:fragment="content">
    <div id="LAY_app" class="layadmin-tabspage-none">
        <div class="layui-layout layui-layout-admin">
            <!-- 头部区域 -->
            <div class="layui-header" role="navigation" th:replace="shared/header :: headerTop"></div>
            <!-- 侧边菜单 -->
            <div class="layui-side layui-side-menu" role="navigation" th:replace="shared/menu :: menuLeft"></div>
            <!-- 主体内容 -->
            <div class="layui-body" id="lemon_main_page" style="margin:5px;padding:10px;background-color: white;">
                <div>
                    <blockquote id="main_tip_1" class="layui-elem-quote">
                        <div style="font-size: 24px;margin-top: 20px;padding: 10px 0">
                            欢迎登录管理系统
                        </div>
                    </blockquote>
                    <div style="display: none">
                        <p>我的菜单</p>
                        <table border="1">
                            <thead>
                            <tr>
                                <td>&emsp;一级路径&emsp;</td>
                                <td>&emsp;一级名称&emsp;</td>
                                <td>&emsp;二级菜单&emsp;</td>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="menu : ${menus}">
                                <td th:text="*{menu.url}"></td>
                                <td th:text="*{'&emsp;'+menu.name+'&emsp;'}"></td>
                                <td>
                                    <div th:each="men : ${menu.child}">
                                        <span th:text="*{'&emsp;'+men.url+'&emsp;'}"></span>|
                                        <span th:text="*{'&emsp;'+men.name+'&emsp;'}"></span>
                                        <hr>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!--加载底部区域-->
            <div class="layui-footer">
                <span>© lcke.xyz - lemon管理系统</span>
            </div>
            <!-- 辅助元素，一般用于移动设备下遮罩 -->
            <div class="layadmin-body-shade" layadmin-event="shade"></div>
        </div>
    </div>
</div>
<!--页面script-->
<script type="application/javascript" layout:fragment="pagescript">
    layui.use(['element', 'layer'], function () {
        var $ = layui.$, element = layui.element, layer = layui.layer;
        // 方法定义
        var lemonadmin = {
            loadContent: function (url) {
                this.events = [];
                $.ajaxSettings.async = false;
                $.get(url, function (html) {
                    $("#lemon_main_page").html(html);
                }, "html");
                $.ajaxSettings.async = true;
            },
            loadPage: function (url) {
                this.loadContent(url);
            },
            logout: function () {
                layer.confirm('您确认要退出吗？', {
                    btn: ['退出系统', '取消'], icon: 3
                }, function () {
                    location.href = "/system/logout";
                    layui.data("")
                    window.localStorage.removeItem('cacheareaList');
                });
            }
        }
        // 点击菜单加载页面
        $(".MenuDDLink").click(function () {
            var url = $(this).attr("data-href");
            if (typeof url === "undefined" || url === "" || url.startsWith("#")) {
                layer.msg("请求路径不存在");
            } else {
                sessionStorage.setItem('menu', url);
                lemonadmin.loadPage(url);
            }
        });

        // 身份信息
        $(".userchange").click(function () {
            var userId = $(this).attr("data-id");
            if (userId === "-1") {
                lemonadmin.logout();
            } else {
                $.post("/system/switch", {"userId": userId}, function (result) {
                    layer.msg(result.msg);
                    if (result.code === 200) {
                        window.location.reload();
                    }
                })
            }
        });
        // 全屏
        $('#BtnFullOpen').on('click', function () {
            var docElm = document.documentElement;
            // W3C
            if (docElm.requestFullscreen) {
                docElm.requestFullscreen();
            }
        });
        // 点击 logo 刷新
        $(".layui-logo").click(() => window.location.reload());
        // 默认展开第一和菜单
        $("#LAY-system-side-menu>li:first").addClass("layui-nav-itemed");
        <!--顶部缩进事件-->
        var $flexible = $("#LAY_app_flexible");
        $flexible.click(function () {
            if ($flexible.hasClass("layui-icon-shrink-right")) {
                $flexible.removeClass("layui-icon-shrink-right").addClass("layui-icon-spread-left");
            } else {
                $flexible.removeClass("layui-icon-spread-left").addClass("layui-icon-shrink-right");
            }
            var $app = $("#LAY_app");
            if ($app.hasClass("layadmin-side-shrink")) {
                $app.removeClass("layadmin-side-shrink");
            } else {
                $app.addClass("layadmin-side-shrink");
            }
        });
        // ajax 增强
        var layerIndex = -1;
        $.ajaxSetup({
            dataType: "json",
            error: function () {
                layer.alert("对不起，页面出错，请联系管理员！");
            },
            beforeSend: function () {
                // layerIndex = layer.load(1, {
                //     shade: [0.5, '#FFF']
                // });
                layerIndex = layer.load(1);
            },
            complete: function (request, status) {
                layer.close(layerIndex);
            }
        });
        // 加载首页

    });
</script>
</body>
</html>
